package com.ewanghuiju.app.ui.my.fragment;

import android.text.TextUtils;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.ewanghuiju.app.R;
import com.ewanghuiju.app.app.Constants;
import com.ewanghuiju.app.base.BaseFragment;
import com.ewanghuiju.app.base.contract.my.ShouyiCenterContract;
import com.ewanghuiju.app.model.bean.response.EarningsInfoBean;
import com.ewanghuiju.app.presenter.my.ShouyiCenterPresenter;
import com.ewanghuiju.app.ui.my.activity.ShouyiCenterActivity;
import com.ewanghuiju.app.util.LoadingDialogUtils;
import com.ewanghuiju.app.util.nodoubleclick.AntiShake;
import com.ewanghuiju.app.widget.popupwindow.CustomTipPopup;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @author sj  qq:751943509
 * @class 收益中心页面
 * @time 2020/2/28
 */
public class ShouyiCenterFragment extends BaseFragment<ShouyiCenterPresenter> implements ShouyiCenterContract.View {
    @BindView(R.id.tv_my_income)
    TextView tvMyIncome;
    @BindView(R.id.tv_my_strokenumber)
    TextView tvMyStrokenumber;
    @BindView(R.id.tv_term_income)
    TextView tvTermIncome;
    @BindView(R.id.tv_term_strokenumber)
    TextView tvTermStrokenumber;
    private int mType;


    @Override
    protected void initInject() {
        getFragmentComponent().inject(this);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.fragment_shouyi_center;
    }

    @Override
    protected void initEventAndData() {
        mType = getArguments().getInt(Constants.SHOUYI_TYPE);
        LoadingDialogUtils.show(activity);
        mPresenter.getPtiprofitCenter(mType + "");
    }

    @Override
    public void showContent(String list) {

    }

    @Override
    public void showMoreContent(String list) {

    }

    @Override
    public void showPtiprofitCenter(EarningsInfoBean bean) {
        //获取收益信息成功
        LoadingDialogUtils.dismissDialog_ios();
        if (bean != null) {

            ((ShouyiCenterActivity) activity).setTextInfo(bean.getYitixian(), bean.getShangyvejiesuan(), bean.getLeijishouyi());

            EarningsInfoBean myEarningsInfoBean = bean.getWode();
            if (myEarningsInfoBean != null) {
                tvMyIncome.setText(TextUtils.isEmpty(myEarningsInfoBean.getWode_income()) ? "0" : myEarningsInfoBean.getWode_income());
                tvMyStrokenumber.setText(TextUtils.isEmpty(myEarningsInfoBean.getWode_pay_number()) ? "0" : myEarningsInfoBean.getWode_pay_number());
            }

            EarningsInfoBean termEarningsInfoBean = bean.getTuandui();
            if (termEarningsInfoBean != null) {
                tvTermIncome.setText(TextUtils.isEmpty(termEarningsInfoBean.getTuandui_income()) ? "0" : termEarningsInfoBean.getTuandui_income());
                tvTermStrokenumber.setText(TextUtils.isEmpty(termEarningsInfoBean.getTuandui_pay_number()) ? "0" : termEarningsInfoBean.getTuandui_pay_number());
            }

        }
    }

    private CustomTipPopup mCustomTipPopup;

    private String mPopupTitle, mPopupContent;

    @OnClick({R.id.tv_my_tip, R.id.tv_team_tip})
    public void doClick(View view) {
        if (AntiShake.check(view.getId())) {    //判断是否多次点击
            return;
        }
        switch (view.getId()) {
            case R.id.tv_my_tip:
                if (mType == 1) {
                    mPopupTitle = getString(R.string.popup_tip_my_sy_title);
                    mPopupContent = getString(R.string.popup_tip_my_shouyi_today_content);
                } else if (mType == 2) {
                    mPopupTitle = getString(R.string.popup_tip_my_sy_title);
                    mPopupContent = getString(R.string.popup_tip_my_shouyi_yestoday_content);
                } else if (mType == 3) {
                    mPopupTitle = getString(R.string.popup_tip_my_sy_title);
                    mPopupContent = getString(R.string.popup_tip_my_shouyi_thismonth_content);
                } else if (mType == 4) {
                    mPopupTitle = getString(R.string.popup_tip_my_sy_title);
                    mPopupContent = getString(R.string.popup_tip_my_shouyi_lastmonth_content);
                }
                if (mCustomTipPopup != null) {
                    mCustomTipPopup.setPopupText(mPopupTitle, mPopupContent);
                    mCustomTipPopup.showPopupWindow();
                    return;
                }
                mCustomTipPopup = new CustomTipPopup(activity, mPopupTitle, mPopupContent
                        , null);
                mCustomTipPopup.setPopupGravity(Gravity.CENTER);
                mCustomTipPopup.showPopupWindow();
                break;
            case R.id.tv_team_tip:
                //提示
                if (mType == 1) {
                    mPopupTitle = getString(R.string.popup_tip_team_sy_title);
                    mPopupContent = getString(R.string.popup_tip_team_shouyi_today_content);
                } else if (mType == 2) {
                    mPopupTitle = getString(R.string.popup_tip_team_sy_title);
                    mPopupContent = getString(R.string.popup_tip_team_shouyi_yestoday_content);
                } else if (mType == 3) {
                    mPopupTitle = getString(R.string.popup_tip_team_sy_title);
                    mPopupContent = getString(R.string.popup_tip_team_shouyi_thismonth_content);
                } else if (mType == 4) {
                    mPopupTitle = getString(R.string.popup_tip_team_sy_title);
                    mPopupContent = getString(R.string.popup_tip_team_shouyi_lastmonth_content);
                }
                if (mCustomTipPopup != null) {
                    mCustomTipPopup.setPopupText(mPopupTitle, mPopupContent);
                    mCustomTipPopup.showPopupWindow();
                    return;
                }
                mCustomTipPopup = new CustomTipPopup(activity, mPopupTitle,
                        mPopupContent, null);
                mCustomTipPopup.setPopupGravity(Gravity.CENTER);
                mCustomTipPopup.showPopupWindow();
                break;
            default:
                break;
        }
    }

    @Override
    public void initImmersionBar() {
//        super.initImmersionBar();
    }
}
